#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/10pf4a/9302012_challenge_102_intermediate_ncharacterset/

require 'optparse'

def ncset(s, c) ; return s.split(//).sort.uniq.size <= c ; end

size = 4
OptionParser.new do |o|
  o.on("-s", "--size=SIZE", Integer) { |size| }
end.parse!

dicts = (! ARGV.empty? ? ARGV : File.basename($0).gsub(/\.rb$/, '.input'))

dicts.each do |dict|
  File.open(dict) do |dict_fh|
    matches = dict_fh.readlines.map { |l| l.strip }.select { |w| ncset(w, size) }.size

    puts "#{dict} : #{matches}"
  end
end
